package com.sms.project;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sms.DB.ConnectDB;
import com.sms.DB.OperateDB;
import com.sms.user.Student;
import com.sms.user.User;

public class PTask {
	private int taskID;
	private int grade;//项目级别
	private String proID;//所属项目
	private String taskType;
	private String content;
	private String fromID;
	private String objectRole;//任务发布者的身份
	private String objectName;//任务发布者的名字
	private String toID;
	private String toName;//接受者的名字
	
	private String startTime;
	private String endTime;
	private String status;
	private String isAppend;
	
	private List<Map> appendFile = null;//项目附件
	
	//初始化一个项目
	public void init(Map map) {
		this.setTaskID((Integer)map.get("taskid"));
		this.setGrade((Integer)map.get("level"));
		this.setProID((String)map.get("taskname"));
		this.setTaskType((String)map.get("task_type"));
		this.setContent((String)map.get("content"));
		this.setFromID((String)map.get("fromid"));
		this.setObjectRole((String)map.get("fromid"));
		this.setObjectName((String)map.get("fromid"));
		this.setToID((String)map.get("toid"));
		this.setToName((String)map.get("toid"));
		this.setStartTime(map.get("starttime").toString());
		this.setEndTime((String)map.get("endtime").toString());
		this.setStatus((String)map.get("status"));
		this.setIsAppend((String)map.get("isappend"));
		if(isAppend.equals("1")) {
			this.setAppendFile((Integer)map.get("taskid"));
		}
	}
	
	public String getToName() {
		return toName;
	}

	public void setToName(String toID) {
		String sql = "select sname from stuinfo where sno = '" + toID + "' ";
		List<Map> list = new ArrayList<Map>();
		list = OperateDB.executeQuery(sql);
		String toname = "";
		
		list = OperateDB.executeQuery(sql);
		if(list.size() > 0) {
			Map map = list.get(0);
			toname = (String)map.get("sname");
		}
		this.toName = toname;
	}

	
	public String getObjectRole() {
		return objectRole;
	}

	public void setObjectRole(String fromID) {
		String sql = "select * from teacherinfo where tno = '" + fromID + "' ";
		List<Map> list = new ArrayList<Map>();
		list = OperateDB.executeQuery(sql);
		if(list != null && list.size() != 0) {
			this.objectRole = "teacher";
		} else {
			this.objectRole = "headman";
		}
	}
	
	public String getObjectName() {
		return objectName;
	}

	public void setObjectName(String fromID) {
		this.objectName = User.getName(this.objectRole, fromID);
	}

	
	public int getTaskID() {
		return taskID;
	}

	public void setTaskID(int taskID) {
		this.taskID = taskID;
	}


	public int getGrade() {
		return grade;
	}


	public void setGrade(int grade) {
		this.grade = grade;
	}


	public String getProID() {
		return proID;
	}


	public void setProID(String proID) {
		this.proID = proID;
	}


	public String getTaskType() {
		return taskType;
	}


	public void setTaskType(String taskType) {
		this.taskType = taskType;
	}


	public String getContent() {
		return content;
	}


	public void setContent(String content) {
		this.content = content;
	}


	public String getFromID() {
		return fromID;
	}


	public void setFromID(String fromID) {
		this.fromID = fromID;
	}


	public String getToID() {
		return toID;
	}


	public void setToID(String toID) {
		this.toID = toID;
	}


	public String getStartTime() {
		return startTime;
	}


	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}


	public String getEndTime() {
		return endTime;
	}


	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}


	public String getStatus() {
		return status;
	}


	public void setStatus(String status) {
		this.status = status;
	}
	
	public List<Map> getAppendFile() {
		return appendFile;
	}
	
	//获取指定文件的附件并设置
	public void setAppendFile(int fileID) {
		String sql = "select * from appendinfo where append_type = '个人任务' " +
				" and fileid = " + fileID;
		List<Map> list = new ArrayList<Map>();
		list = OperateDB.executeQuery(sql);
		if(list.size() > 0) {//有附件时才初始化appendPath对象
			appendFile = new ArrayList<Map>();
			for(int i=0; i<list.size(); i++) {
				Map map = list.get(i);
				String fileName = (String)map.get("filename");
				String saveName = (String)map.get("savename");
				Map<String, String> map2 = new HashMap<String, String>();
				map2.put("fileName", fileName);
				map2.put("saveName", saveName);
				appendFile.add(map2);
			}
		}
	}
	
	public String getIsAppend() {
		return isAppend;
	}
	
	public void setIsAppend(String isAppend) {
		this.isAppend = isAppend;
	}
	
	
}



